package com.zbkj.service.model.dto.address;

import com.zbkj.dal.entity.merchant.Merchant;
import com.zbkj.dal.entity.user.UserAddress;
import lombok.Data;
import org.springframework.lang.Nullable;

@Data
public class OrderAddressCreateDTO {
    private Integer linkAddressId;
    private Integer provinceCode;
    private String provinceName;
    private Integer cityCode;
    private String cityName;
    private Integer regionCode;
    private String regionName;
    private Integer townCode;
    private String townName;
    private String address;
    private String contactName;
    private String contactPhone;


    public static OrderAddressCreateDTO buildByUserAddress(@Nullable UserAddress userAddress) {
        if (userAddress == null) {
            return null;
        }
        OrderAddressCreateDTO orderAddressCreateDTO = new OrderAddressCreateDTO();
        orderAddressCreateDTO.setLinkAddressId(userAddress.getId());
        orderAddressCreateDTO.setProvinceCode(userAddress.getProvinceId());
        orderAddressCreateDTO.setProvinceName(userAddress.getProvince());
        orderAddressCreateDTO.setCityCode(userAddress.getCityId());
        orderAddressCreateDTO.setCityName(userAddress.getCity());
        orderAddressCreateDTO.setRegionCode(userAddress.getDistrictId());
        orderAddressCreateDTO.setRegionName(userAddress.getDistrict());
        orderAddressCreateDTO.setAddress(userAddress.getDetail());
        orderAddressCreateDTO.setContactName(userAddress.getRealName());
        orderAddressCreateDTO.setContactPhone(userAddress.getPhone());
        return orderAddressCreateDTO;
    }

    public static OrderAddressCreateDTO buildByMerchantAddress(Merchant merchant) {
        if (merchant == null) {
            return null;
        }
        OrderAddressCreateDTO orderAddressCreateDTO = new OrderAddressCreateDTO();
        orderAddressCreateDTO.setLinkAddressId(merchant.getId());
        orderAddressCreateDTO.setProvinceCode(merchant.getProvinceId());
        orderAddressCreateDTO.setProvinceName(merchant.getProvince());
        orderAddressCreateDTO.setCityCode(merchant.getCityId());
        orderAddressCreateDTO.setCityName(merchant.getCity());
        orderAddressCreateDTO.setRegionCode(merchant.getDistrictId());
        orderAddressCreateDTO.setRegionName(merchant.getDistrict());
        orderAddressCreateDTO.setAddress(merchant.getAddressDetail());
        orderAddressCreateDTO.setContactName(merchant.getRealName());
        orderAddressCreateDTO.setContactPhone(merchant.getPhone());
        return orderAddressCreateDTO;
    }
}
